import React from 'react'
import {useSelector,useDispatch} from 'react-redux';
import { addGoodsAction, getCartListAction, removeGoodsAction } from '../redux/actions/cartAction';
function Cart() {
  let dispatch = useDispatch();
   let list  = useSelector((state)=>{
    return state.cartReducer.list
   })
   if(list.length===0){
    dispatch(getCartListAction())
   }
    return (
      <div>
           <div>Cart</div>
           <ol>
            {
              list.map((item,index)=>{
                return <li key={index}>{item.storeName}</li>
              })
            }
           </ol>
           <button onClick={()=>{
            dispatch(addGoodsAction({storeName:"汽水"}))
           }}>添加商品</button>
      </div>
    )
  }
export default Cart
